/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NovoChamado1.java
 *
 * Created on Nov 23, 2011, 12:52:15 AM
 */
package br.fesppr.sacob.gui;

import br.fesppr.sacob.dao.AtendimentoDAO;
import br.fesppr.sacob.dao.PessoaDAO;
import br.fesppr.sacob.dto.AtendimentoDTO;
import br.fesppr.sacob.dto.PessoaDTO;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author chrestenzen
 */
public class NovoChamado extends javax.swing.JFrame {

    /** Creates new form NovoChamado1 */
    public NovoChamado() {
        initComponents();
        calendar = Calendar.getInstance();
        txtData.setText("" + calendar.get(Calendar.DAY_OF_MONTH) + (calendar.get(Calendar.MONTH) + 1) + calendar.get(Calendar.YEAR));
            AtendimentoDAO daoa = new AtendimentoDAO();
        try {
            txtProt.setText(Integer.toString(daoa.contadorProtocolo()));
        } catch (SQLException ex) {
            Logger.getLogger(NovoChamado.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        lblDate = new javax.swing.JLabel();
        try
        {
            MaskFormatter formatterData = new MaskFormatter("##/##/####");
            formatterData.setPlaceholderCharacter('_');
            txtData = new javax.swing.JFormattedTextField(formatterData);
            lblProt = new javax.swing.JLabel();
            MaskFormatter formatterProtocolo = new MaskFormatter("##");
            txtProt = new javax.swing.JFormattedTextField(formatterProtocolo);
            jSeparator2 = new javax.swing.JSeparator();
            jLabel2 = new javax.swing.JLabel();
            lblCpfClie = new javax.swing.JLabel();
            try{
                MaskFormatter formatterCpf = new MaskFormatter("###.###.###-##");
                formatterCpf.setPlaceholderCharacter('_');
                txtCpf = new javax.swing.JFormattedTextField(formatterCpf);
                btnPesq = new javax.swing.JButton();
                lblNomeClie = new javax.swing.JLabel();
                txtNome = new javax.swing.JTextField();
                jSeparator3 = new javax.swing.JSeparator();
                jLabel7 = new javax.swing.JLabel();
                comboTipoAtendimento = new javax.swing.JComboBox();
                jLabel8 = new javax.swing.JLabel();
                txtProduto = new javax.swing.JTextField();
                jLabel9 = new javax.swing.JLabel();
                jScrollPane1 = new javax.swing.JScrollPane();
                txtChamado = new javax.swing.JTextArea();
                lblStatus = new javax.swing.JLabel();
                comboStatus = new javax.swing.JComboBox();
                lblPrioridade = new javax.swing.JLabel();
                comboPrioridade = new javax.swing.JComboBox();
                btnRegistraChamado = new javax.swing.JButton();

                setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
                setTitle("SACOB - Abertura de Atendimentos\n");
                setResizable(false);

                jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 12));
                jLabel1.setForeground(new java.awt.Color(3, 3, 3));
                jLabel1.setText("SACOB - Sistema de Atendimento ao Cliente Belíssima ");

                lblDate.setFont(new java.awt.Font("DejaVu Sans", 0, 10));
                lblDate.setText("Data:");

            }
            catch(Exception e)
            {
            }

            lblProt.setFont(new java.awt.Font("DejaVu Sans", 0, 10));
            lblProt.setText("Protocolo:");

            txtProt.setEditable(false);

            jLabel2.setFont(new java.awt.Font("DejaVu Sans", 1, 10));
            jLabel2.setText("Dados do Cliente");

            lblCpfClie.setFont(new java.awt.Font("DejaVu Sans", 0, 12));
            lblCpfClie.setText("CPF do Cliente:");

        }
        catch(Exception e)
        {
        }

        btnPesq.setFont(new java.awt.Font("DejaVu Sans", 0, 12));
        btnPesq.setText("Buscar");
        btnPesq.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPesqActionPerformed(evt);
            }
        });

        lblNomeClie.setFont(new java.awt.Font("DejaVu Sans", 0, 12));
        lblNomeClie.setText("Nome do Cliente:");

        txtNome.setEditable(false);
        txtNome.setFont(new java.awt.Font("DejaVu Sans", 0, 10));

        jLabel7.setFont(new java.awt.Font("DejaVu Sans", 1, 10));
        jLabel7.setText("Tipo do Atendimento");

        comboTipoAtendimento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Solicitação", "Dúvida", "Reclamação" }));
        comboTipoAtendimento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboTipoAtendimentoActionPerformed(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("DejaVu Sans", 1, 10));
        jLabel8.setText("Produto");

        jLabel9.setFont(new java.awt.Font("DejaVu Sans", 1, 10));
        jLabel9.setText("Descrição do Chamado");

        txtChamado.setColumns(20);
        txtChamado.setFont(new java.awt.Font("DejaVu Sans", 0, 12));
        txtChamado.setRows(5);
        jScrollPane1.setViewportView(txtChamado);

        lblStatus.setFont(new java.awt.Font("DejaVu Sans", 1, 10));
        lblStatus.setText("Status do Chamado:");

        comboStatus.setFont(new java.awt.Font("DejaVu Sans", 0, 10));
        comboStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Em Andamento", "Pendente", "Concluído" }));
        comboStatus.setToolTipText("");

        lblPrioridade.setFont(new java.awt.Font("DejaVu Sans", 1, 10));
        lblPrioridade.setText("Prioridade:");

        comboPrioridade.setFont(new java.awt.Font("DejaVu Sans", 0, 10));
        comboPrioridade.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Normal", "Urgente" }));
        comboPrioridade.setToolTipText("");

        btnRegistraChamado.setFont(new java.awt.Font("DejaVu Sans", 0, 12));
        btnRegistraChamado.setText("Registrar Chamado");
        btnRegistraChamado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRegistraChamadoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(107, Short.MAX_VALUE)
                .addComponent(lblDate)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblProt)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtProt, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(111, 111, 111))
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2)
                .addContainerGap(337, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(42, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblNomeClie)
                        .addGap(1, 1, 1))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblCpfClie, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(2, 2, 2)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnPesq))
                    .addComponent(txtNome))
                .addGap(75, 75, 75))
            .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 430, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(comboTipoAtendimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 200, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(83, 83, 83))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(txtProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addContainerGap(306, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblStatus)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(comboStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(89, 89, 89)
                        .addComponent(lblPrioridade)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(comboPrioridade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 410, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(58, 58, 58)
                .addComponent(jLabel1)
                .addContainerGap(61, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(145, 145, 145)
                .addComponent(btnRegistraChamado)
                .addContainerGap(144, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDate)
                    .addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblProt)
                    .addComponent(txtProt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCpfClie)
                    .addComponent(btnPesq)
                    .addComponent(txtCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNomeClie)
                    .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboTipoAtendimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboPrioridade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblPrioridade))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnRegistraChamado)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnPesqActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPesqActionPerformed
        // TODO add your handling code here:
        PessoaDTO pessoa =  new PessoaDTO();
        PessoaDAO dao = new PessoaDAO();
        
        pessoa = dao.listaPorCPF(txtCpf.getText());
        
        txtNome.setText(pessoa.getNome());
        
        
        
        
      
}//GEN-LAST:event_btnPesqActionPerformed

private void comboTipoAtendimentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTipoAtendimentoActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_comboTipoAtendimentoActionPerformed

private void btnRegistraChamadoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegistraChamadoActionPerformed
        AtendimentoDTO AtendimentoDTO = null;
        // TODO add your handling code here:
        
        AtendimentoDTO atendimento = new AtendimentoDTO();
        AtendimentoDAO daoa = new AtendimentoDAO();
        PessoaDTO pessoadto = new PessoaDTO();
        
        atendimento.setProtocolo(Integer.parseInt(txtProt.getText()));
        atendimento.setDescricao(txtChamado.getText());
        atendimento.setTipoAtendimento(comboTipoAtendimento.getSelectedItem().toString());
        atendimento.setStatus(comboStatus.getSelectedItem().toString());
        atendimento.setPrioridade(comboPrioridade.getSelectedItem().toString());
        atendimento.setProduto(txtProduto.getText());
        atendimento.setNomeCliente(txtNome.getText());
        atendimento.setData(txtData.getText());
        if(txtNome == null)
        {
            JOptionPane.showMessageDialog(null, "Favor informar o nome do cliente","SACOB",0);
        }
        else
        {
        daoa.geraAtendimento(atendimento);
        }
       
        
       // JOptionPane.showMessageDialog(this, "Chamado Registrado com Sucesso", "SACOB", JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_btnRegistraChamadoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(NovoChamado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NovoChamado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NovoChamado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NovoChamado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new NovoChamado().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnPesq;
    private javax.swing.JButton btnRegistraChamado;
    private javax.swing.JComboBox comboPrioridade;
    private javax.swing.JComboBox comboStatus;
    private javax.swing.JComboBox comboTipoAtendimento;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JLabel lblCpfClie;
    private javax.swing.JLabel lblDate;
    private javax.swing.JLabel lblNomeClie;
    private javax.swing.JLabel lblPrioridade;
    private javax.swing.JLabel lblProt;
    private javax.swing.JLabel lblStatus;
    private javax.swing.JTextArea txtChamado;
    private javax.swing.JFormattedTextField txtCpf;
    private javax.swing.JFormattedTextField txtData;
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtProduto;
    private javax.swing.JFormattedTextField txtProt;
    // End of variables declaration//GEN-END:variables
    private Calendar calendar;
}
